import "../css/animate.min.css"
import "../css/case-info.css"

//整合首页用到的所有js
import {
    getCaseInfo
} from "./request.js";

let imgs = document.querySelectorAll("img")
let caseImg = document.querySelectorAll(".photo>ul>li>img")

//图片添加类名进行懒加载
imgs.forEach(item => {
    item.classList.add("lazy-img")
})

import {
    lazyLoad
} from "../utils/lazyLoad.js";
window.onload = async function () {
    let resInfo = await getCaseInfo();
    let res = resInfo.results
    let address = [];
    //拿到每个图片的地址
    res.forEach((item)=>{
        address.push(item.photo_detail.url)
    })
    //将每张图片地址给到每个img
    imgs.forEach((item,index)=>{
        item.setAttribute("data-src",address[index])
    })


    //懒加载
    lazyLoad(".lazy-img");
};

//给每张图片添加事件
let flag = true;
caseImg.forEach((item,index)=>{
    item.addEventListener("mouseover",()=>{
        item.classList.add("move")
    })
    item.addEventListener("mouseout",()=>{
        item.classList.remove("move")
    })
    item.addEventListener("click",()=>{
        flag = !flag
        if(!flag){
            if(index === 0 ){
                item.classList.add("aF")
            }else if(index === 1){
                item.classList.add("bF")
            }else if(index === 2){
                item.classList.add("cF")
            }else if(index === 3){
                item.classList.add("dF")
            }else if(index === 4){
                item.classList.add("eF")
            }else if(index ===5){
                item.classList.add("fF")
            }else if(index === 6){
                item.classList.add("gF")
            }else{
                item.classList.add("hF")
            }
        }else{
            if(index === 0 ){
                item.classList.remove("aF")
            }else if(index === 1){
                item.classList.remove("bF")
            }else if(index === 2){
                item.classList.remove("cF")
            }else if(index === 3){
                item.classList.remove("dF")
            }else if(index === 4){
                item.classList.remove("eF")
            }else if(index ===5){
                item.classList.remove("fF")
            }else if(index === 6){
                item.classList.remove("gF")
            }else{
                item.classList.remove("hF")
            }
        }
    })
})